from django.db import models
from goods.models import Product
from users.models import UserInfo
from datetime import datetime


# Create your models here.
# 可以多级评论  但是前端就显示两层级
class Comment(models.Model):
    """
    新增自关联
    评论表对应产品   用label表示不同的产品   借鉴淘宝
    """
    user = models.ForeignKey(to=UserInfo, verbose_name='用户', on_delete=models.CASCADE)
    good = models.ForeignKey(to=Product, verbose_name='商品', on_delete=models.CASCADE)
    parent_id = models.ForeignKey('self', null=True, blank=True, related_name='sub_cat', default='',
                                  verbose_name='父级分类',
                                  on_delete=models.CASCADE)
    content = models.TextField(verbose_name='评论')
    rate = models.FloatField(verbose_name='评分')
    zan = models.SmallIntegerField(verbose_name='点赞')
    add_time = models.DateTimeField(verbose_name='添加时间', default=datetime.now)


class CommentImage(models.Model):
    """
    评论图片
    """
    comment = models.ForeignKey(to=Comment, verbose_name='所属评论', on_delete=models.CASCADE)
    image = models.ImageField(verbose_name='评论图', upload_to='banner/%Y/%m/%d')
    add_time = models.DateTimeField(verbose_name='添加时间', default=datetime.now)
